//
//  RGMeWalletVC.m
//  RedGrass
//
//  Created by wuyine on 2018/12/19.
//  Copyright © 2018年 hongcaosp. All rights reserved.
//

#import "RGMeWalletVC.h"
#import "HAHorizontalCollectionFlowLayout.h"
@implementation RGMeWalletPriceCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.layer.borderColor = [UIColor whiteColor].CGColor;
        self.layer.borderWidth = 2;
        self.layer.cornerRadius = 10;
        self.layer.masksToBounds = YES;
        
        [self.contentView addSubview:self.priceLabel];
        [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(0);
        }];
    }
    return self;
}

- (void)setSelected:(BOOL)selected {
    if (selected) {
        self.backgroundColor = UICOLOR_WITH_RGBINT(0x333333);
        self.layer.borderColor = UICOLOR_WITH_RGBINT(0xf73152).CGColor;
        self.priceLabel.textColor = UICOLOR_WITH_RGBINT(0xf73152);
    }else {
        self.backgroundColor = UICOLOR_WITH_RGBINT(0x000000);
        self.layer.borderColor = UICOLOR_WITH_RGBINT(0xffffff).CGColor;
        self.priceLabel.textColor = UICOLOR_WITH_RGBINT(0xffffff);
    }
}

- (UILabel *)priceLabel {
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.textColor = [UIColor whiteColor];
        _priceLabel.text = @"6元";
        _priceLabel.font = FONT(customFontName, 14);
    }
    return _priceLabel;
}

@end

@implementation RGMeWalletCashCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor blackColor];
        [self.contentView addSubview:self.icon];
        [self.contentView addSubview:self.title];
        [self.contentView addSubview:self.subTitle];
        UILabel *tip = [[UILabel alloc] init];
        tip.textColor = UICOLOR_WITH_RGBINT(0x999999);
        tip.font = FONT(customFontNameLight, 12);
        tip.text = @"点击提现";
        UIImageView *arrow = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"设置_更多")];
        [self.contentView addSubview:tip];
        [self.contentView addSubview:arrow];
        
        [_icon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(20);
            make.size.mas_equalTo(CGSizeMake(27.5, 27.5));
            make.centerY.mas_equalTo(0);
        }];
        
        [_title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.icon.mas_trailing).offset(10);
            make.top.equalTo(self.icon.mas_top).offset(-5);
        }];
        
        [_subTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.icon.mas_trailing).offset(10);
            make.bottom.equalTo(self.icon.mas_bottom).offset(5);
        }];
        
        [arrow mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.mas_equalTo(-20);
            make.size.mas_equalTo(CGSizeMake(7, 14));
            make.centerY.mas_equalTo(0);
        }];
        
        [tip mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.equalTo(arrow.mas_leading).offset(-10);
            make.centerY.mas_equalTo(0);
        }];
    }
    return self;
}

- (UIImageView *)icon {
    if (!_icon) {
        _icon = [[UIImageView alloc] init];
    }
    return _icon;
}

- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        _title.textColor = UICOLOR_WITH_RGBINT(0xffffff);
        _title.font = FONT(customFontNameLight, 14);
    }
    return _title;
}

- (UILabel *)subTitle {
    if (!_subTitle) {
        _subTitle = [[UILabel alloc] init];
        _subTitle.textColor = UICOLOR_WITH_RGBINT(0x999999);
        _subTitle.font = FONT(customFontNameLight, 12);
        _subTitle.text = @"每笔提现最低5元";
    }
    return _subTitle;
}

@end

@implementation RGMeWalletHeaderView

- (instancetype)init {
    if (self = [super init]) {
        self.backgroundColor = [UIColor blackColor];
        [self addSubview:self.titleLabel];
        [self addSubview:self.moneyLabel];
        [self addSubview:self.tipLabel];
        
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.top.mas_equalTo(15);
        }];
        
        [_moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(20);
        }];
        
        [_tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.equalTo(self.moneyLabel.mas_bottom).offset(6);
            make.bottom.mas_equalTo(-5);
        }];
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 10)];
        [btn setImage:IMAGE_NAMED(@"arrow_right") forState:UIControlStateNormal];
//        [btn addTarget:self action:@selector(moreClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.moneyLabel.mas_trailing).offset(0);
            make.centerY.equalTo(self.moneyLabel.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(40, 40));
        }];
        
        UIButton *bigBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//        [btn setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 10)];
//        [btn setImage:IMAGE_NAMED(@"arrow_right") forState:UIControlStateNormal];
        [bigBtn addTarget:self action:@selector(moreClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:bigBtn];
        [bigBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.moneyLabel.mas_leading).offset(-50);
            make.centerY.equalTo(self.moneyLabel.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(200, 40));
        }];
        
    }
    return self;
}


- (void)moreClick {
    if (self.more) {
        self.more();
    }
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.font = FONT(customFontName, 14);
    }
    return _titleLabel;
}

- (UILabel *)moneyLabel {
    if (!_moneyLabel) {
        _moneyLabel = [[UILabel alloc] init];
        _moneyLabel.textColor = [UIColor whiteColor];
        _moneyLabel.font = FONT(customFontName, 28);
    }
    return _moneyLabel;
}

- (UILabel *)tipLabel {
    if (!_tipLabel) {
        _tipLabel = [[UILabel alloc] init];
        _tipLabel.textColor = [UIColor whiteColor];
        _tipLabel.font = FONT(customFontName, 12);
    }
    return _tipLabel;
}

@end

@implementation RGMeWalletPayCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.icon];
        [self.contentView addSubview:self.title];
        [_icon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(15);
            make.centerY.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(25, 23.5));
        }];
        
        [_title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.icon.mas_trailing).offset(20);
            make.centerY.mas_equalTo(0);
        }];
    }
    return self;
}

- (UIImageView *)icon {
    if (!_icon) {
        _icon = [[UIImageView alloc] init];
    }
    return _icon;
}

- (UILabel *)title {
    if (!_title) {
        _title = [[UILabel alloc] init];
        _title.textColor = UICOLOR_WITH_RGBINT(0x333333);
        _title.font = FONT(customFontNameLight, 16);
    }
    return _title;
}

@end

@interface RGMePayView()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) UIView *header;
@property (nonatomic,strong) UIView *footer;
@end

@implementation RGMePayView
- (instancetype)init {
    if (self = [super init]) {
        self.backgroundColor = UICOLOR_WITH_RGBINT(0xffffff);
        [self addSubview:self.tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(UIEdgeInsetsZero);
        }];
    }
    return self;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    RGMeWalletPayCell *cell = [tableView dequeueReusableCellWithIdentifier:@"payCell"];
    if (indexPath.row == 0) {
        cell.title.text = @"微信";
        cell.icon.image = IMAGE_NAMED(@"微信支付");
    }else {
        cell.title.text = @"支付宝";
        cell.icon.image = IMAGE_NAMED(@"支付宝支付");
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 48;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (void)cancel:(UIButton *)btn {
    [self setNeedsUpdateConstraints];
    [UIView animateWithDuration:0.5 animations:^{
        [self mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(-(48*4+SafeAreaBottomHeight));
        }];
    } completion:^(BOOL finished) {
        if (finished) {
            [self removeFromSuperview];
        }
    }];
    [self.superview layoutIfNeeded];
}

- (void)showInView:(UIView *)view {
    [view addSubview:self];
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(0);
        make.bottom.mas_equalTo(-(48*4+SafeAreaBottomHeight));
        make.height.mas_equalTo(48*4+SafeAreaBottomHeight);
    }];
    
    [self setNeedsUpdateConstraints];
    [UIView animateWithDuration:0.5 animations:^{
        [self mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(0);
        }];
    }];
    [self.superview layoutIfNeeded];
}

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] init];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[RGMeWalletPayCell class] forCellReuseIdentifier:@"payCell"];
        _tableView.scrollEnabled = NO;
        _tableView.tableFooterView = self.footer;
        _tableView.tableHeaderView = self.header;
        [_tableView setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];
    }
    return _tableView;
}

- (UIView *)header {
    if (!_header) {
        _header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 48)];
        UILabel *title = [[UILabel alloc] init];
        title.textColor = UICOLOR_WITH_RGBINT(0x999999);
        title.font = FONT(customFontName, 14);
        title.text = @"选择支付方式";
        [_header addSubview:title];
        [title mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(0);
            make.leading.mas_equalTo(15);
        }];
        UIView *line = [[UIView alloc] init];
        line.backgroundColor = UICOLOR_WITH_RGBINT(0xcccccc);
        [_header addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(0);
            make.leading.mas_equalTo(15);
            make.trailing.mas_equalTo(-15);
            make.height.mas_equalTo(0.2);
        }];
    }
    return _header;
}

- (UIView *)footer {
    if (!_footer) {
        _footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 48)];
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.titleLabel.font = FONT(customFontName, 14);
        [btn setTitle:@"取消" forState:UIControlStateNormal];
        [btn setTitleColor:UICOLOR_WITH_RGBINT(0xf73152) forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
        [_footer addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(KScreenWidth, 48));
        }];
        UIView *line = [[UIView alloc] init];
        line.backgroundColor = UICOLOR_WITH_RGBINT(0xcccccc);
        [_footer addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.leading.mas_equalTo(15);
            make.trailing.mas_equalTo(-15);
            make.height.mas_equalTo(0.2);
        }];
        
    }
    return _footer;
}
@end
#import "RGWalletRecordsVC.h"
#import "RGMeWalletInterfaceBuilder.h"
#import "UIScrollView+EmptyDataSet.h"
#import "RGWalletModel.h"
#import "RGRechargeModel.h"
#import "RGWithdrawCashViewController.h"
#import "XLMShareSdkTool.h"

#define PayView_Tag 100
@interface RGMeWalletVC ()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic,strong) UIScrollView *scrollView;
@property (nonatomic,strong) UITableView *cashTableView;
@property (nonatomic,strong) RGMeWalletHeaderView *cashHeader;
@property (nonatomic,strong) UICollectionView *priceCollectionView;
@property (nonatomic,strong) RGMeWalletHeaderView *priceHeader;
@property (nonatomic,strong) UILabel *payMoneyLabel;
@property (nonatomic,strong) UIButton *payBtn;
@property (nonatomic,strong) NSIndexPath *lastIndexPath;
@property (nonatomic,strong) RGMePayView *payView;
@property (nonatomic,strong) RGWalletModel *walletModel;
@property (nonatomic,strong) NSArray *dataList;
@end

@implementation RGMeWalletVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self showBackButton];
    self.customContentView.backgroundColor = [UIColor blackColor];
    self.customNavBar.title = @"钱包";
    [self initUI];
    [self upateMoneyCountWithCount:@"0"];
    [self loadData];
}

- (void)initUI {
    [self.customContentView addSubview:self.scrollView];
    [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsZero);
    }];
    UIView *canzhao = [[UIView alloc] init];
    canzhao.backgroundColor = [UIColor blackColor];
    [_scrollView addSubview:canzhao];
    [canzhao mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.trailing.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
        make.width.equalTo(self.scrollView.mas_width);
    }];
    [_scrollView addSubview:self.priceHeader];
    AA_WEAK_MAKE(self) weakSelf = self;
    [self.priceHeader setMore:^{
        RGWalletRecordsVC *vc = [[RGWalletRecordsVC alloc] init];
        vc.emptyTitle = @"你还没有充值记录哦";
        vc.type = ReCharge;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    [_priceHeader mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.mas_equalTo(0);
    }];

    [_scrollView addSubview:self.payMoneyLabel];
    [_payMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.equalTo(self.priceHeader.mas_bottom).offset(152);
    }];

    [_scrollView addSubview:self.payBtn];
    [_payBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(200, 40));
        make.top.equalTo(self.payMoneyLabel.mas_bottom).offset(10);
    }];

    UIView *line = [[UIView alloc] init];
    line.backgroundColor = UICOLOR_WITH_RGBINT(0x999999);
    [_scrollView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(15);
        make.trailing.mas_equalTo(0);
        make.top.equalTo(self.payBtn.mas_bottom).offset(20);
        make.height.mas_equalTo(0.5);
    }];

    [_scrollView addSubview:self.cashHeader];
    [self.cashHeader setMore:^{
        RGWalletRecordsVC *vc = [[RGWalletRecordsVC alloc] init];
        vc.emptyTitle = @"你还没有提现记录哦";
        vc.type = Cash;
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
    [_cashHeader mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(0);
//         make.top.leading.trailing.mas_equalTo(0);
        make.top.equalTo(line.mas_bottom).offset(0);
    }];
    
    [_scrollView addSubview:self.cashTableView];
    [_cashTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.bottom.mas_equalTo(0);
        make.height.mas_equalTo(120);
        make.top.equalTo(self.cashHeader.mas_bottom);
    }];

}

- (void)initCollectionView {
    [_scrollView addSubview:self.priceCollectionView];
    [_priceCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.priceHeader.mas_bottom);
        make.leading.trailing.mas_equalTo(0);
        make.height.mas_equalTo(150);
    }];
}

- (void)loadData {
    __block HttpRequest *quest = [HttpRequest buildRequest:url_userWallet];
    NSDictionary *params = [RGMeWalletInterfaceBuilder buildRechargeListWithOperationType:ReCharge];
    AA_WEAK_MAKE(self) weakSelf = self;
    [quest post:params success:^(id data) {
        weakSelf.walletModel = [[RGWalletModel alloc] initWithDictionary:[data objectForKey:@"userWallet"] error:nil];
        NSLog(@"rr");
        NSString *dStr = [NSString stringWithFormat:@"%f", weakSelf.walletModel.redAmount.doubleValue];
        [weakSelf upateMoneyCountWithCount:[NSDecimalNumber decimalNumberWithString:dStr].stringValue];
        quest = [HttpRequest buildRequest:url_rechargeList];
        NSDictionary *params = [RGMeWalletInterfaceBuilder buildRechargeListWithOperationType:ReCharge];
        [quest post:params success:^(id data) {
            [weakSelf dismissLoading];
            weakSelf.dataList = [RGRechargeModel arrayOfModelsFromDictionaries:[data objectForKey:@"list"] error:nil];
            [weakSelf initCollectionView];
            [weakSelf collectionView:weakSelf.priceCollectionView didSelectItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
        } fail:^(NSInteger code, NSString *message) {
            [weakSelf showTextMessageWithMessage:message];
        }];
    } fail:^(NSInteger code, NSString *message) {
        [weakSelf showTextMessageWithMessage:message];
    }];
}

-(void) upateMoneyCountWithCount:(NSString *)count{
    if([count length] == 0){
        count = @"0";
    }
    NSString *countLabel = [NSString stringWithFormat:@"%@元",count];
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:countLabel];
    NSRange range = [countLabel rangeOfString:@"元"];
    NSDictionary *dic = @{NSFontAttributeName : FONT(customFontName, 10)};
    [attr addAttributes:dic range:range];
    self.cashHeader.moneyLabel.attributedText = attr;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    RGMeWalletCashCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cashCell"];
    switch (indexPath.row) {
        case 0: {
            cell.icon.image = IMAGE_NAMED(@"微信");
            cell.title.text = @"提现到微信";
        }
            break;
        case 1: {
            cell.icon.image = IMAGE_NAMED(@"支付宝");
            cell.title.text = @"提现到支付宝";
        }
            break;
        default:
            break;
    }
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if(self.walletModel == nil){
        return;
    }
    NSString *dStr = [NSString stringWithFormat:@"%f", self.walletModel.redAmount.doubleValue];
    NSDecimalNumber *money = [[NSDecimalNumber alloc]initWithString:dStr];
    if(money == nil || [money floatValue] < 5){
        [self showTextMessageWithMessage:@"单笔提现金额不能少于5元"];
        return;
    }
    
    if(!self.walletModel.isBindWx){//没有绑定，进行进行绑定
        AA_WEAK_MAKE(self)weakSelf = self;
        [[XLMShareSdkTool shareInstance] setLoginBlock:^(BOOL success, NSDictionary *dic) {

            if(success){
                NSString *code = [dic objectForKey:@"code"];
                [weakSelf bandWeixiAccountWithCode:SafeStr(code)];
            }else{
                [weakSelf showTextMessageWithMessage:@"绑定微信账号失败，请重试"];
            }
        }];
        [XLMShareSdkTool thirdLoginWithWeChatResult];
        
    }else{
        
        RGWithdrawCashViewController *vc = [[RGWithdrawCashViewController alloc]init];
        NSString *dStr = [NSString stringWithFormat:@"%f", self.walletModel.redAmount.doubleValue];
        vc.cash = dStr;
        AA_WEAK_MAKE(self)weaSelf = self;
        [vc setNeedUpdateBlock:^{
           [weaSelf loadData];
        }];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

#pragma mark - interface
-(void) bandWeixiAccountWithCode:(NSString *)code{
    [self showLoading:@""];
    AA_WEAK_MAKE(self) weakSelf = self;
    HttpRequest *quest = [HttpRequest buildRequest:@"/api/user/bindingPayType"];
    RGUserInfoModel *user = [RGUserInfoModel getUserInfo];
    NSDictionary *dic = @{@"token":SafeStr(user.token),
                          @"type":@(1),
                          @"account":SafeStr(code)};
    [quest post:dic success:^(id data) {
        NSLog(@"data = %@",data);
        [weakSelf dismissLoading];
        RGWithdrawCashViewController *vc = [[RGWithdrawCashViewController alloc]init];
        NSString *dStr = [NSString stringWithFormat:@"%f", weakSelf.walletModel.redAmount.doubleValue];
        vc.cash = [NSDecimalNumber numberWithString:dStr].stringValue;
        [vc setNeedUpdateBlock:^{
            [weakSelf loadData];
        }];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    } fail:^(NSInteger code, NSString *message) {
         [weakSelf showTextMessageWithMessage:@"绑定微信账号失败，请重试"];
    }];
}


#pragma mark - colletctionView delegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataList.count;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    return CGSizeMake(KScreenWidth/3-25, 50);
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    RGMeWalletPriceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"priceCell" forIndexPath:indexPath];
    RGRechargeModel *model = [self.dataList objectAtIndex:indexPath.row];
    cell.priceLabel.text = [NSString stringWithFormat:@"%@元",model.payPrice];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    RGMeWalletPriceCell *lastCell = (RGMeWalletPriceCell*)[collectionView cellForItemAtIndexPath:self.lastIndexPath];
    lastCell.backgroundColor = UICOLOR_WITH_RGBINT(0x000000);
    lastCell.layer.borderColor = UICOLOR_WITH_RGBINT(0xffffff).CGColor;
    lastCell.priceLabel.textColor = UICOLOR_WITH_RGBINT(0xffffff);
    
    RGMeWalletPriceCell *cell = (RGMeWalletPriceCell*)[collectionView cellForItemAtIndexPath:indexPath];
    cell.backgroundColor = UICOLOR_WITH_RGBINT(0x333333);
    cell.layer.borderColor = UICOLOR_WITH_RGBINT(0xf73152).CGColor;
    cell.priceLabel.textColor = UICOLOR_WITH_RGBINT(0xf73152);
    
    self.lastIndexPath = indexPath;
    RGRechargeModel *model = [self.dataList objectAtIndex:indexPath.row];
    _payMoneyLabel.text = [NSString stringWithFormat:@"支付金额：%@元",model.payPrice];
}

- (void)pay:(UIButton *)btn {
    if (![self.view viewWithTag:PayView_Tag]) {
        [self.payView showInView:self.view];
    }
}

#pragma mark --getter
- (UIScrollView *)scrollView {
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc] init];
        _scrollView.backgroundColor = [UIColor blackColor];
    }
    return _scrollView;
}

- (UICollectionView *)priceCollectionView {
    if (!_priceCollectionView) {
//        HAHorizontalCollectionFlowLayout *layout = [[HAHorizontalCollectionFlowLayout alloc] init];
//        layout.itemCountPerRow = 3;
//        layout.rowCount = ceil(self.dataList.count/3)>0 ?ceil(self.dataList.count/3):1;
//        layout.itemSize = CGSizeMake(KScreenWidth/3-15, 50);
//        layout.minimumInteritemSpacing = 0;
//        layout.sectionInset = UIEdgeInsetsMake(5, 15, 5, 15);
//        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.minimumInteritemSpacing = 0;
        flowLayout.minimumLineSpacing = 0;
        flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        flowLayout.sectionInset = UIEdgeInsetsMake(5, 15, 5, 15);
        _priceCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 150) collectionViewLayout:flowLayout];
        _priceCollectionView.backgroundColor = [UIColor blackColor];
        _priceCollectionView.showsHorizontalScrollIndicator = NO;
        _priceCollectionView.pagingEnabled = YES;
        [_priceCollectionView registerClass:[RGMeWalletPriceCell class] forCellWithReuseIdentifier:@"priceCell"];
        _priceCollectionView.delegate = self;
        _priceCollectionView.dataSource = self;
    }
    return _priceCollectionView;
}

- (UITableView *)cashTableView {
    if (!_cashTableView) {
        _cashTableView = [[UITableView alloc] init];
        _cashTableView.backgroundColor = [UIColor blackColor];
        [_cashTableView registerClass:[RGMeWalletCashCell class] forCellReuseIdentifier:@"cashCell"];
        _cashTableView.tableFooterView = [UIView new];
        _cashTableView.scrollEnabled = NO;
        _cashTableView.delegate = self;
        _cashTableView.dataSource = self;
        _cashTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _cashTableView;
}

- (RGMeWalletHeaderView *)cashHeader {
    if (!_cashHeader) {
        _cashHeader = [[RGMeWalletHeaderView alloc] init];
        _cashHeader.titleLabel.text = @"提现";
        _cashHeader.tipLabel.text = @"可提现金额";
//        _cashHeader.moneyLabel.text = @"0元";
    }
    return _cashHeader;
}

- (RGMeWalletHeaderView *)priceHeader {
    if (!_priceHeader) {
        _priceHeader = [[RGMeWalletHeaderView alloc] init];
        _priceHeader.titleLabel.text = @"充值";
        _priceHeader.tipLabel.text = @"余额";
        _priceHeader.moneyLabel.text = @"0元";
    }
    return _priceHeader;
}

- (UILabel *)payMoneyLabel {
    if (!_payMoneyLabel) {
        _payMoneyLabel = [[UILabel alloc] init];
        _payMoneyLabel.textColor = [UIColor whiteColor];
        _payMoneyLabel.text = @"支付金额：6元";
        _payMoneyLabel.font = FONT(customFontName, 12);
    }
    return _payMoneyLabel;
}

- (UIButton *)payBtn {
    if (!_payBtn) {
        _payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_payBtn setTitle:@"确认支付" forState:UIControlStateNormal];
        [_payBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _payBtn.titleLabel.font = FONT(customFontName, 14);
        _payBtn.layer.cornerRadius = 4;
        _payBtn.backgroundColor = UICOLOR_WITH_RGBINT(0xf73152);
        [_payBtn addTarget:self action:@selector(pay:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _payBtn;
}

- (RGMePayView *)payView {
    if (!_payView) {
        _payView = [[RGMePayView alloc] init];
        _payView.tag = PayView_Tag;
    }
    return _payView;
}

@end
